home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-02-12 | 4.3 KB | 186 lines | [TEXT/PJMM] |
- {wSample -- the Mac User Education prog, adapted to use wMenus}
- { by Jim Matthews }
- PROGRAM wSample;
- {$I-}
- USES
- wMenu;
- CONST
- appleID = 128;
- fileID = 129;
- editID = 130;
-
- appleM = 1;
- fileM = 2;
- editM = 3;
-
- menuCount = 3;
-
- windowID = 128;
-
- undoCommand = 1;
- cutCommand = 3;
- copyCommand = 4;
- pasteCommand = 5;
- clearCommand = 6;
-
- VAR
- myMenus : ARRAY[1..menuCount] OF MenuHandle;
- dragRect, txRect : Rect;
- textH : TEHandle;
- theChar : char;
- extended, doneFlag : boolean;
- myEvent : EventRecord;
- wRecord : WindowRecord;
- myWindow : WindowPtr;
- whichWindow : WindowPtr;
- myMenuBar : wMenuBarHandle;
-
- {SetUpWMenus -- read in menu templates and set up wMenuBar}
- PROCEDURE SetUpWMenus;
- VAR
- i : integer;
- BEGIN
- myMenuBar := wInitMenus(myWindow);
- myMenus[appleM] := GetMenu(appleID);
- AddResMenu(myMenus[appleM], 'DRVR');
- myMenus[fileM] := GetMenu(fileID);
- myMenus[editM] := GetMenu(editID);
-
- FOR i := 1 TO menuCount DO
- wInsertMenu(myMenuBar, myMenus[i], 0);
- END; {SetUpWMenus}
-
- {DoCommand -- handle menu commands}
- PROCEDURE DoCommand (mResult : longint);
- VAR
- theItem, theMenu : integer;
- name : Str255;
- temp : integer;
- BEGIN
- theItem := LoWord(mResult);
- theMenu := HiWord(mResult);
-
- CASE theMenu OF
- appleID :
- BEGIN
- GetItem(myMenus[appleM], theItem, name);
- temp := OpenDeskAcc(name);
- SetPort(myWindow);
- END; { appleID }
- fileID :
- doneflag := true;
- editID :
- BEGIN
- IF NOT SystemEdit(theItem - 1) THEN
- CASE theItem OF
- cutCommand :
- TECut(textH);
- copyCommand :
- TECopy(textH);
- pasteCommand :
- TEPaste(textH);
- clearCommand :
- TEDelete(textH);
- END; { case theItem of }
- END; { editID}
- OTHERWISE
- ;
- END; { case theMenu of }
- wHiliteMenu(myMenuBar, 0);
- END; { DoCommand }
-
- {main program}
- BEGIN
- InitGraf(@thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
-
- WITH screenBits.bounds DO
- SetRect(dragRect, 4, 24, right - 4, bottom - 4);
- doneFlag := false;
- myWindow := GetNewWindow(windowID, @wRecord, WindowPtr(-1));
- SetPort(myWindow);
- SetUpWMenus;
- txRect := thePort^.portRect;
- txRect.top := mBarHeight;
- InsetRect(txRect, 3, 3);
- textH := TENew(txRect, txRect);
-
- {main event loop}
- REPEAT
- SystemTask;
- TEIdle(textH);
-
- IF GetNextEvent(everyEvent, myEvent) THEN
- CASE myEvent.what OF
- mouseDown :
- CASE FindWindow(myEvent.where, whichWindow) OF
- inSysWindow :
- SystemClick(myEvent, whichWindow);
- inMenuBar :
- IF MenuSelect(myEvent.where) <> 0 THEN
- ; { handle da menus in the "real" menu bar }
- inDrag :
- DragWindow(whichWindow, myEvent.where, dragRect);
- inContent :
- BEGIN
- GlobalToLocal(myEvent.where);
- IF myEvent.where.v < mBarHeight THEN
- BEGIN
- IF whichWindow <> FrontWindow THEN
- SelectWindow(whichWindow);
- DoCommand(wMenuSelect(myMenuBar, myEvent.where));
- END
- ELSE
- BEGIN
- IF whichWindow <> FrontWindow THEN
- SelectWindow(whichWindow)
- ELSE
- BEGIN
- extended := BitAnd(myEvent.modifiers, shiftKey) <> 0;
- TEClick(myEvent.where, extended, textH);
- END; { whichWindow = FrontWindow}
- END; { click below menu bar }
- END; { inContent }
- OTHERWISE
- ;
- END; { mouseDown }
- keyDown, autoKey :
- BEGIN
- theChar := char(BitAnd(myEvent.message, charCodeMask));
- IF BitAnd(myEvent.modifiers, cmdKey) <> 0 THEN
- DoCommand(wMenuKey(myMenuBar, theChar))
- ELSE
- TEKey(theChar, textH);
- END; { keyDown, autoKey }
- activateEvt :
- BEGIN
- IF BitAnd(myEvent.modifiers, activeFlag) <> 0 THEN
- BEGIN
- TEActivate(textH);
- DisableItem(myMenus[editM], undoCommand);
- END
- ELSE
- BEGIN
- TEDeactivate(textH);
- EnableItem(myMenus[editM], undoCommand);
- END; { activate/deactivate }
- END; {activateEvt }
- updateEvt :
- BEGIN
- BeginUpdate(WindowPtr(myEvent.message));
- EraseRect(thePort^.portRect);
- wDrawMenuBar(myMenuBar);
- TEUpdate(thePort^.portRect, textH);
- EndUpdate(WindowPtr(myEvent.message));
- END; { updateEvt }
- OTHERWISE
- ;
- END; { case event.what of }
- UNTIL doneFlag;
- END.